import Vue from 'vue'
import md5 from 'js-md5';

Vue.prototype.$md5 = md5;

Vue.prototype.$loginUser = __LONG_USER__


import ElementUI from 'element-ui'

import './common/element-variables.scss'
// import 'element-ui/lib/theme-chalk/index.css'

import globalCss from '@/common/base.less'

Vue.prototype.$globalCss = globalCss;

import '@/common/app-base.less'
import '@/common/app-common.less';

import '@/asset/iconfont/iconfont.css';
import App from '@/app.vue'

import HaiguiExUI from 'galileo-ex-ui'

import Decimal from 'decimal.js';

Vue.prototype.$math_add = function (...nums) {
  try {
    return nums.reduce((sum, it) => sum.add(Decimal(it ? it : 0)), Decimal(0)).toNumber()
  } catch (e) {
    return Number.NaN
  }
};
Vue.prototype.$math_sub = function (num, tonum) {
  try {
    return Decimal(num ? num : 0).sub(Decimal(tonum ? tonum : 0)).toNumber()
  } catch (e) {
    return Number.NaN
  }
};
Vue.prototype.$math_mul = function (...nums) {
  try {
    return nums.reduce((sum, it) => sum.mul(Decimal(it ? it : 0)), Decimal(1)).toNumber()
  } catch (e) {
    return Number.NaN
  }
};
Vue.prototype.$math_div = function (num, tonum) {
  try {
    return Decimal(num ? num : 0).div(Decimal(tonum ? tonum : 0)).toNumber()
  } catch (e) {
    return Number.NaN
  }
};
Vue.prototype.$math_round = function (num, decimal,number = true) {
  try {
    const value = Decimal(num ? num : 0).toFixed(decimal ? decimal : 0)
    return number? Number(value):value
  } catch (e) {
    return Number.NaN
  }
};
Vue.prototype.$math_ceil = function (num, decimal = 0,number = true) {
  try {
    const value = Decimal(num ? num : 0).toFixed(decimal ? decimal : 0, Decimal.ROUND_UP)
    return number? Number(value):value
  } catch (e) {
    return Number.NaN
  }
}
Vue.prototype.$math_toFixed = function (num, decimal) {
  try {
    return Decimal(num ? num : 0).toFixed(decimal)
  } catch (e) {
    return Number.NaN
  }
}
import cache from '@/common/cache'

Vue.use(cache);

// 加载自定义控件
HaiguiExUI.install(Vue)

// 为上传控件设置上传、下载 url
Vue.prototype.$ex_default_upload_url = '/ums-api/client/ResourceClientRpc/upload.json'
Vue.prototype.$ex_default_download_url = '/aliyun_oss/download/'

// 登陆 url ，默认为 '/login.htm'
Vue.prototype.$ex_default_login_url = '/login.htm'

import sysInit from './common/sys-init.js'

Vue.use(sysInit)




ElementUI.Dialog.props.modalAppendToBody.default = false
ElementUI.Dialog.props.appendToBody.default = false
ElementUI.Dialog.props.top.default = ""


//Vuex状态管理
import store from './store'
// Vue.prototype.$store = store;
// import VueI18n from 'vue-i18n';
//国际化使用
import i18n_main from './i18n';
// Vue.use(VueI18n);
// const i18n = new VueI18n(i18n_main);
import VueI18n from 'vue-i18n';

Vue.use(VueI18n);
const i18n = new VueI18n(i18n_main);
Vue.prototype.$i18nEl = i18n
Vue.use(ElementUI, {
  size: 'small',
  i18n: function (path, options) {
    return i18n.t(path, options)
  }
})
import component_init from './common/component_init'

Vue.use(component_init)

import router from './router/_router'

Vue.prototype.$tt = (path, option) => {
  if (path) {
    if (path instanceof Array) {
      if (!option) {
        option = ' '
      } else {
        option = option.separate || option
      }
      return path.map(it => i18n.t(it)).join(option)
    } else if (path instanceof Object) {
      const { _key, ...other } = path
      return Vue.prototype.$tt(_key, other)
    } else if (typeof (path) === 'string') {
      path = path.trim()
    }
    if (option instanceof Object) {
      const { i18n:i18nConfig, ..._op } = option
      if (i18nConfig instanceof Object) {
        _.forOwn(_op, (v, k) => {
          if (!!i18nConfig[k]) {
            _op[k] = Vue.prototype.$tt(v)
          }
        })
      } else if (i18nConfig) {
        _.forOwn(_op, (v, k) => {
          _op[k] = Vue.prototype.$tt(v)
        })
      } else {

      }
      return Vue.prototype.$formatReg(i18n.t(path), _op)
    } else {
      return i18n.t(path)
    }
  }
  return ''
}
if (new RegExp(/((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))/).test(window.location.hostname)) {
  Vue.config.errorHandler = function (err, vm, info) {
    console.error(err, vm, info)
    Vue.prototype.$notify.error({
      title: 'vue js 运行错误',
      message: err
    });
  }
}
Vue.mixin({
  beforeCreate() {
    this.$emit("beforeCreateEmit", this)
  },
})


window._AMapSecurityConfig = {
  // 设置安全密钥
  securityJsCode: "99087c0e00a68ec2f875fad86391786f"
}
const checkIsEmpty = _.isEmpty
_.isEmpty = function (value) {
  if (typeof (value) == 'number') {
    return checkIsEmpty(String(value))
  }
  return checkIsEmpty(value)
}
new Vue({
  router,
  i18n: i18n,
  store,
  render: h => h(App),
  beforeCreate() {
    Vue.prototype.$bus = this//安装全局事件总线
    Vue.prototype._ = _
  }
}).$mount('#app')
